package songgao.papers.iEC;

import java.util.ArrayList;


public enum MigrationStrategies {
	INSTANCE;
	private SimpleAnnularMigrationStrategy simpleAnnularMigrationStrategy = new SimpleAnnularMigrationStrategy();

	public class SimpleAnnularMigrationStrategy implements MigrationStrategy {

		@Override
		public void migrate(ArrayList<Population> populationPool) {
			for (Integer i = 0;i<populationPool.size();i++) {
				int target = i.equals(DataManager.INSTANCE.getParameters().getPopulationPoolSize() - 1) ? 0 : i + 1;
				int individualIndex = DataManager.INSTANCE.getRandomizer().nextInt(populationPool.get(i).getIndividualKeys().size());
				populationPool.get(target).getIndividualKeys().add(populationPool.get(i).getIndividualKeys().get(individualIndex));
			}
		}

	}

	public MigrationStrategy getMigrationStrategy(String migrationStrategyName) {
		if (migrationStrategyName.toLowerCase().equals("SimpleAnnularMigrationStrategy".toLowerCase()))
			return this.simpleAnnularMigrationStrategy;

		return null;
	}
}
